#!/usr/bin/python
    #Copyright 2006 Andrew Wilkinson <andrew@indiegigs.co.uk>

    #This file is part of libfixed.

    #libfixed is free software; you can redistribute it and/or modify
    #it under the terms of the GNU General Public License as published by
    #the Free Software Foundation; either version 2 of the License, or
    #(at your option) any later version.

    #libfixed is distributed in the hope that it will be useful,
    #but WITHOUT ANY WARRANTY; without even the implied warranty of
    #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    #GNU General Public License for more details.

    #You should have received a copy of the GNU General Public License
    #along with libfixed; if not, write to the Free Software
    #Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

import os

tests = ["create16", "create32", "addition16", "addition32", "subtract16", "subtract32", "multiply16", "multiply32", "divide16", "divide32", "round16", "sin16", "sin32", "cos16", "cos32", "pow16", "exp16"]

def compare(expect, actual):
    _pass, fail = 0, 0
    lines = zip(expect.strip().split("\n"), actual.strip().split("\n"))
    for e, a in lines:
        if len(a) == 0:
            fail += 1
        elif float(e) != float(a):
            fail += 1
        else:
            _pass += 1
    longest = max(expect.split("\n"), actual.split("\n"))
    if len(lines) > longest:
        fail += longest - len(lines)
    return _pass, fail

_pass, fail = 0, 0
for test in tests:
    print test, "...",
    output = os.popen("%s/%s" % (test, test)).read()
    expected = open("%s/expected.txt" % (test,)).read()
    open("%s/actual.txt" % (test,), "w").write(output)
    p, f = compare(expected, output)
    if f == 0:
        print "pass",
        _pass += 1
    else:
        print "fail",
        fail += 1
    print "(%i, %i)" % (p, f)

print "Pass: ", _pass
print "Fail: ", fail
